package com.vedana.bankmobile.services;

import java.util.List;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.vedana.bankmobile.dao.AccountDao;
import com.vedana.bankmobile.dao.CustomerDao;
import com.vedana.bankmobile.dao.OperationDao;
import com.vedana.bankmobile.dao.impl.AccountDatastoreDao;
import com.vedana.bankmobile.dao.impl.CustomerDatastoreDao;
import com.vedana.bankmobile.dao.impl.OperationDatastoreDao;
import com.vedana.bankmobile.shared.Account;
import com.vedana.bankmobile.shared.Customer;
import com.vedana.bankmobile.shared.Operation;

/**
 * BankMobile generic remote service.<br/>
 * This service is used by RPC adapters (GWT, JSON, Protobuf, Flex remoting).
 * 
 * @author Didier MOISE
 *
 */
public class BankMobileServiceImpl implements BankMobileService {
	/* (non-Javadoc)
	 * @see com.vedana.bankmobile.services.IBankMobileService#getAllOperations(long)
	 */
	@Override
	public List<Operation> getAllOperations(long accountId) {
		DatastoreService datastore = DatastoreServiceFactory
		.getDatastoreService();

		OperationDao dao = new OperationDatastoreDao(datastore);
		
		return dao.listOperations(accountId);
	}
	
	/* (non-Javadoc)
	 * @see com.vedana.bankmobile.services.IBankMobileService#getCustomerList(java.lang.String)
	 */
	@Override
	public List<Customer> getCustomerList(String userId) {
		DatastoreService datastore = DatastoreServiceFactory
		.getDatastoreService();

		CustomerDao dao = new CustomerDatastoreDao(datastore);
		
		return dao.listCustomers(userId);
	}

	/* (non-Javadoc)
	 * @see com.vedana.bankmobile.services.IBankMobileService#getAccountList(long)
	 */
	@Override
	public List<Account> getAccountList(long customerId) {
		DatastoreService datastore = DatastoreServiceFactory
		.getDatastoreService();

		AccountDao dao = new AccountDatastoreDao(datastore);
		
		return dao.listAccounts(customerId);
	}

	/* (non-Javadoc)
	 * @see com.vedana.bankmobile.services.IBankMobileService#getRangeOfOperations(long, int, int)
	 */
	@Override
	public List<Operation> getRangeOfOperations(long accountId, int start, int length) {
		DatastoreService datastore = DatastoreServiceFactory
		.getDatastoreService();

		OperationDao dao = new OperationDatastoreDao(datastore);
		
		return dao.listOperationsRange(accountId, start, length);		
	}
}
